﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lunexx
{
    static class ConsoleWrapper
    {
        static ConsoleWrapper()
        {
            ForegroundColor = Console.ForegroundColor;
            BackgroundColor = Console.BackgroundColor;
            Console.SetWindowSize((int)(Console.LargestWindowWidth - Console.LargestWindowHeight * 0.8) ,Console.LargestWindowHeight / 2);
            Debug = 9;
            LogLevel = 9;
            Break = true;

        }

        #region Properties

        /// <summary>
        ///   Value that sets whether or not to output debug information to console, higher values = more debug information outputted.
        /// </summary>
        /// <remarks>
        ///   <list>
        ///     -1 = Will output that an error has occured, but no further information will be given.
        ///     0 = No debug information will be displayed.
        ///     1+ = Output debug information including exception (if applicable).
        ///   </list>
        /// </remarks>
        public static sbyte Debug { get; set; }

        public static byte LogLevel { get; set; }

        /// <summary>
        ///   Sets the console background ConsoleColor
        /// </summary>
        public static ConsoleColor BackgroundColor
        {
            get { return Console.BackgroundColor; }
            set { Console.BackgroundColor = value; }
        }

        public static bool Break { get; set; }

        /// <summary>
        ///   Sets the console foreground ConsoleColor
        /// </summary>
        public static ConsoleColor ForegroundColor
        {
            get { return Console.ForegroundColor; }
            set { Console.ForegroundColor = value; }
        }

        #endregion

        #region Methods

        #region Extends System.Console

        public static void DebugWrite(string debugInfo, sbyte debugLevel)
        {
            if(Debug <= -1) WriteLineColor("[Error] An error has occured.",ConsoleColor.Black,ConsoleColor.Red);
            if (Debug == 0) return;
            if (debugLevel <= Debug)
            {
                WriteLineColor("[Error] " + debugInfo,ConsoleColor.Black,ConsoleColor.Red);
                if (Break) Console.ReadKey();
            }
        }

        public static void WriteColorFG(string input, ConsoleColor fgcolor)
        {
            Console.ForegroundColor = fgcolor;
            Console.Write(input);
            Console.ResetColor();
        }

        public static void WriteColor(string input, ConsoleColor fgcolor, ConsoleColor bgcolor)
        {
            Console.ForegroundColor = fgcolor;
            Console.BackgroundColor = bgcolor;
            Console.Write(input);
            Console.ResetColor();
        }

        public static void WriteColorBG(string input, ConsoleColor bgcolor)
        {
            Console.BackgroundColor = bgcolor;
            Console.Write(input);
            Console.ResetColor();
        }

        public static void WriteLineColor(string input, ConsoleColor fgcolor, ConsoleColor bgcolor)
        {
            Console.ForegroundColor = fgcolor;
            Console.BackgroundColor = bgcolor;
            Console.WriteLine(input);
            Console.ResetColor();
        }

        public static void WriteLineColorFG(string input, ConsoleColor fgcolor)
        {
            Console.ForegroundColor = fgcolor;
            Console.WriteLine(input);
            Console.ResetColor();
        }

        public static void WriteLineColorBG(string input, ConsoleColor bgcolor)
        {
            Console.BackgroundColor = bgcolor;
            Console.WriteLine(input);
            Console.ResetColor();
        }

        public static void MasterWriteLine(string input, byte loglevel)
        {
            if (LogLevel == 0) return;
            if (loglevel <= LogLevel)
            {
                WriteColor("[Master]",ConsoleColor.Black,ConsoleColor.Green);
                Write(" ");
                WriteLine(input);
            }
        }

        public static void WorldWriteLine(string input, byte loglevel)
        {
            if (LogLevel == 0) return;
            if (loglevel <= LogLevel)
            {
                WriteColor("[World]",ConsoleColor.Blue,ConsoleColor.Green);
                Write(" ");
                WriteLine(input);
            }
        }

        public static void DisplayBanner()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("      ___       ___           ___           ___           ___           ___     ");
            Console.WriteLine("     /\\__\\     /\\__\\         /\\__\\         /\\  \\         |\\__\\         |\\__\\    ");
            Console.WriteLine("    /:/  /    /:/  /        /::|  |       /::\\  \\        |:|  |        |:|  |   ");
            Console.WriteLine("   /:/  /    /:/  /        /:|:|  |      /:/\\:\\  \\       |:|  |        |:|  |   ");
            Console.WriteLine("  /:/  /    /:/  /  ___   /:/|:|  |__   /::\\~\\:\\  \\      |:|__|__      |:|__|__ ");
            Console.WriteLine(" /:/__/    /:/__/  /\\__\\ /:/ |:| /\\__\\ /:/\\:\\ \\:\\__\\ ____/::::\\__\\ ____/::::\\__\\");
            Console.WriteLine(" \\:\\  \\    \\:\\  \\ /:/  / \\/__|:|/:/  / \\:\\~\\:\\ \\/__/ \\::::/~~/~    \\::::/~~/~   ");
            Console.WriteLine("  \\:\\  \\    \\:\\  /:/  /      |:/:/  /   \\:\\ \\:\\__\\    ~~|:|~~|      ~~|:|~~|    ");
            Console.WriteLine("   \\:\\  \\    \\:\\/:/  /       |::/  /     \\:\\ \\/__/      |:|  |        |:|  |    ");
            Console.WriteLine("    \\:\\__\\    \\::/  /        /:/  /       \\:\\__\\        |:|  |        |:|  |    ");
            Console.WriteLine("     \\/__/     \\/__/         \\/__/         \\/__/         \\|__|         \\|__|    ");
            Console.WriteLine("");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("                        ___           ___           ___           ___           ___           ___           ___     ");
            Console.WriteLine("                       /\\  \\         /\\  \\         /\\__\\         /\\__\\         /\\  \\         /\\  \\         /\\  \\    ");
            Console.WriteLine("                      /::\\  \\       /::\\  \\       /:/  /        /::|  |       /::\\  \\       /::\\  \\       /::\\  \\   ");
            Console.WriteLine("                     /:/\\:\\  \\     /:/\\:\\  \\     /:/  /        /:|:|  |      /:/\\:\\  \\     /:/\\:\\  \\     /:/\\:\\  \\  ");
            Console.WriteLine("                    /::\\~\\:\\__\\   /:/  \\:\\  \\   /:/  /  ___   /:/|:|  |__   /:/  \\:\\  \\   /::\\~\\:\\  \\   /::\\~\\:\\  \\ ");
            Console.WriteLine("                   /:/\\:\\ \\:|__| /:/__/ \\:\\__\\ /:/__/  /\\__\\ /:/ |:| /\\__\\ /:/__/ \\:\\__\\ /:/\\:\\ \\:\\__\\ /:/\\:\\ \\:\\__\\");
            Console.WriteLine("                   \\:\\~\\:\\/:/  / \\:\\  \\ /:/  / \\:\\  \\ /:/  / \\/__|:|/:/  / \\:\\  \\  \\/__/ \\:\\~\\:\\ \\/__/ \\/_|::\\/:/  /");
            Console.WriteLine("                    \\:\\ \\::/  /   \\:\\  /:/  /   \\:\\  /:/  /      |:/:/  /   \\:\\  \\        \\:\\ \\:\\__\\      |:|::/  / ");
            Console.WriteLine("                     \\:\\/:/  /     \\:\\/:/  /     \\:\\/:/  /       |::/  /     \\:\\  \\        \\:\\ \\/__/      |:|\\/__/  ");
            Console.WriteLine("                      \\::/__/       \\::/  /       \\::/  /        /:/  /       \\:\\__\\        \\:\\__\\        |:|  |    ");
            Console.WriteLine("                       ~~            \\/__/         \\/__/         \\/__/         \\/__/         \\/__/         \\|__|    ");
            Console.ResetColor();
            Console.WriteLine("Running Rev: {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
            Console.WriteLine("");
            Console.WriteLine("");
        }

        #endregion Extends System.Console

        #region Encapsulates System.Console
        public static void Write(string input)
        {
            Console.Write(input);
        }

        public static void WriteLine(string line)
        {
            Console.WriteLine(line);
        }

        public static void ResetColor()
        {
            Console.ResetColor();
        }

        #endregion Encapsulates System.Console

        #endregion
    }
}
